package org.or5e.oss.core;

import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.Logger;

public abstract class BaseObject {
	private Logger _logger = null;
	private static Properties _props = null;
	
	static {
		_props = new Properties();
		try {
			_props.load(ClassLoader.getSystemResourceAsStream("core.properties"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * Super Class Constructor, where the Logging gets Initialized.
	 */
	public BaseObject() {
		_logger = Logger.getLogger(getName());
	}

	/**
	 * This method will provide all the API classes of setting a property and gives leverage to be accessed across the API classes. It is specially designed to provide the Inter-Class Communication. 
	 * @param key
	 * @param value
	 */
	public final void setProperty(String key, String value) {
		_props.setProperty(key, value);
	}
	
	/**
	 * This method will provide all the API classes of getting an property and gives leverage to be accessed across the API classes. It is specially designed to provide the Inter-Class Communication. 
	 * @param key
	 * @return
	 */
	public final Object getProperty(String key) {
		return _props.getProperty(key);
	}

	/**
	 * This method will provide all the API classes of setting a property and gives leverage to be accessed across the API classes. It is specially designed to provide the Inter-Class Communication. 
	 * @param key
	 * @param value
	 */
	public final void put(String key, Object value) {
		_props.put(key, value);
	}

	/**
	 * This method will provide all the API classes of getting an property and gives leverage to be accessed across the API classes. It is specially designed to provide the Inter-Class Communication.
	 * @param key
	 * @return
	 */
	public final Object get(String key) {
		return _props.get(key);
	}


	/**
	 * This method will provide the logging functionality for any API Classes - WARN Logger 
	 * @param message
	 */
	public final void warn(Object message) {
		this._logger.warn(message);
	}

	/**
	 * This method will provide the logging functionality for any API Classes - ERROR Logger 
	 * @param message
	 */
	public final void error(Object message) {
		this._logger.error(message);
	}

	/**
	 * This method will provide the logging functionality for any API Classes - DEBUG Logger 
	 * @param message
	 */
	public final void debug(Object message) {
		this._logger.debug(message);
	}

	/**
	 * This method will provide the logging functionality for any API Classes - INFO Logger 
	 * @param message
	 */
	public final void info(Object message) {
		this._logger.info(message);
	}

	/**
	 * Abstract method to support the logger mechanism. Any class wants the logging mechanism is said to be extend this class and override this method to return the name of the class 
	 * @return
	 */
	public abstract String getName();
}